function TITTInputStream(xhr) {
	
	var dataRead = false, sis = null, HTTP_NEWLINE = TITTValues.HTTP_NEWLINE;
	
	this.read = function(len) {
		readAllData();
		return sis.read(len);
	}
	
	this.readLine = function() {
		readAllData();
		return sis.readLine();
	}
	
	this.readFully = function() {
		readAllData();
		return sis.readFully();
	}
	
	this.close = function() {
		dataRead = false;
		sis = null;
	}
	
	function readAllData() {
		if(dataRead) return;

		/*
		 * #NOTICE#
		 * 
		 * nightly build of safari (20100420) bugs here. xhr status is 0.
		 */

		var stat = "HTTP/1.1 " + xhr.status + " " + xhr.statusText;
		var head = xhr.getAllResponseHeaders();
				
		//check that the newlines used is according to the protocol
		if(head.indexOf(HTTP_NEWLINE) == -1)
			head = head.replace(/\n/g, HTTP_NEWLINE);
			
		//check if the head ends with a empty line - if not add one
		if(head.indexOf(HTTP_NEWLINE+HTTP_NEWLINE) == -1)
			head = head + HTTP_NEWLINE;

		var data = stat + HTTP_NEWLINE + head + xhr.responseText;

		sis = new StaticInputStream(data);
		dataRead = true;

	}
}
